<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
//use App\Model\Admin\Admin;
class OrdersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
      $data = DB::table('orders')
        ->join('user','user.id', '=', 'orders.user_id')         
        ->select('user.nickname','orders.*')
        ->get();

        //dd($data);
        return view('admin.orders_list',['orders'=>$data]);
       
       
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function send($id)
    {
       DB::table('orders')->where('id',$id)->update(['send'=>1]);
       return redirect('/admin/orders');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
         $data1 = DB::table('user')
        ->join('orders','user.id', '=', 'orders.user_id')
        ->select('user.username','orders.status','orders.time')
        ->where('orders.id',$id)       
        ->first();





       $data2 = DB::table('orders_info')
        ->join('goods','orders_info.goods_id', '=', 'goods.id')
        ->select('goods.goods_name','orders_info.num','goods.goods_price','goods.goods_des')
        ->where('orders_info.orders_id',$id)
        ->get();



        return view('admin.orders_show',['orders1'=>$data1,'orders2'=>$data2]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
       // return view('admin.admin_edit',['id'=>$id]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
   
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    //删除订单
    public function del($id)
    {
      /*return $id;
        die;*/
        DB::table('orders')->where('id',$id)->delete();
        return response()->json(['status' => '200']);
    }
  

  
}